﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Irrlicht.Net.Core;

namespace Irrlicht.Net.Video
{    
    public enum VertexTypes
    {
        Standard = 0,
        Coords2T,
        Tangents
    };
 
 
    /*string[] BuiltInVertexTypeNames =
    {
         "standard",
         "2tcoords",
         "tangents"
    };*/

    public class Vertex3D
    {
        internal Vector3D pos;
        internal Vector3D normal;
        internal Color color;
        internal Vector2D tCoords;

        public Vertex3D(float x, float y, float z, float nx, float ny, float nz, Color c, float tu, float tv)
        {
            this.pos = new Vector3D(x, y, z);
            this.normal = new Vector3D(nx, ny, nz);
            this.color = c;
            this.tCoords = new Vector2D(tu, tv);
        }

        public Vertex3D(Vector3D pos, Vector3D normal, Color color, Vector2D tcoords)
        {
            this.pos = pos;
            this.normal = normal;
            this.color = color;
            this.tCoords = tcoords;
        }

        public Vector3D Pos
        {
            get
            {
                return pos;
            }
        }

        public Vector3D Normal
        {
            get
            {
                return normal;
            }
        }
        
        public Vector2D TCoords
        {
            get
            {
                return tCoords;
            }
        }

        public Color Color
        {
            get
            {
                return color;
            }
        }

        public VertexTypes Type
        {
            get
            {
                return VertexTypes.Standard;
            }
        }

        public static bool operator == (Vertex3D vertex1, Vertex3D vertex2)
        {                 
            return ((vertex1.Pos == vertex2.Pos) && (vertex1.Normal == vertex2.Normal) &&         
                (vertex1.Color == vertex2.Color) && (vertex1.TCoords == vertex2.TCoords));
        }
 
        public static bool operator!= (Vertex3D vertex1, Vertex3D vertex2)
        {        
            return ((vertex1.Pos != vertex2.Pos) || (vertex1.Normal != vertex2.Normal) ||                      
                (vertex1.Color != vertex2.Color) || (vertex1.TCoords != vertex2.TCoords));
        }

        public static bool operator <(Vertex3D vertex1, Vertex3D vertex2)
        {
            return ((vertex1.Pos < vertex2.Pos) ||                                 
                ((vertex1.Pos == vertex2.Pos) && (vertex1.Normal < vertex2.Normal)) ||                
                ((vertex1.Pos == vertex2.Pos) && (vertex1.Normal == vertex2.Normal) && (vertex1.Color < vertex2.Color)) ||                
                ((vertex1.Pos == vertex2.Pos) && (vertex1.Normal == vertex2.Normal) && (vertex1.Color == vertex2.Color) && (vertex1.TCoords < vertex2.TCoords)));
        }

        public static bool operator >(Vertex3D vertex1, Vertex3D vertex2)
        {
            return ((vertex1.Pos > vertex2.Pos) ||
                ((vertex1.Pos == vertex2.Pos) && (vertex1.Normal > vertex2.Normal)) ||
                ((vertex1.Pos == vertex2.Pos) && (vertex1.Normal == vertex2.Normal) && (vertex1.Color > vertex2.Color)) ||
                ((vertex1.Pos == vertex2.Pos) && (vertex1.Normal == vertex2.Normal) && (vertex1.Color == vertex2.Color) && (vertex1.TCoords > vertex2.TCoords)));
        }

        public override bool Equals(object obj)
        {
            if (obj is Vertex3D)
            {
                return (this == (Vertex3D)obj);
            }
            else
            {
                return false;
            }
        }

        public override int GetHashCode()
        {
            return (Convert.ToInt32(Pos.X + Pos.Y + Pos.Z + Normal.X + Normal.Y + Normal.Z + TCoords.X + TCoords.Y) + (int)Color.ColorValue);
        }
    }
}
